package com.flyme.excel.validator;

import com.ycc.vins.excel.ExcelCellValidator;
import com.ycc.vins.util.ValidateResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Nullable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by lijizhong on 2017/12/14.
 */
@Service
public class LegalDateFormatValidator implements ExcelCellValidator {

    @Nullable
    @Override
    public ValidateResult apply(String s) {
        if (StringUtils.isBlank(s)) {
            return ValidateResult.pass();
        }
        if (StringUtils.isBlank(s)) {
            return ValidateResult.pass();
        }
        try {
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            format.setLenient(false);
            Date date = format.parse(s);
            return ValidateResult.pass();
        } catch (Exception e) {
            return ValidateResult.notPass("日期不合法");
        }
    }
}
